<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link href="<%=basePath %>bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
    <script src="<%=basePath %>bootstrap/js/jquery.min.js"></script>
    <script src="<%=basePath %>bootstrap/js/bootstrap.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
    <script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>
</head>
<body>

<div class="col-md-12" >
    <div id="toolbar" class="btn-group">
        <button id="btn_save" type="button" class="btn btn-default " data-toggle="modal" data-target="#modalTable" >
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>复制绑定关系
        </button>

    </div>
    <table id="reportTable" ></table>
</div>

<div class="modal fade" id="modalTable" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">参考科室</h4>
            </div>
            <div class="modal-body">
                <table id="referdeptable"
                       data-toggle="table"
                       data-height="360"
                       data-search="true"
                       data-single-select="true"
                       data-click-to-select="true"
                       data-url="../dept/selectAllDept" style="table-layout: fixed;">
                    <thead>
                    <tr>
                        <th data-checkbox="true"></th>
                        <th data-field="name" >部门名称</th>

                    </tr>
                    </thead>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"  id="btn_sure">确定</button>
            </div>
        </div>
    </div>
</div>
<form action="<%=basePath%>deptMapper/addDeptPaperForm" method="post" name="form1">

    <input type="hidden" id="deptid" name="deptid">
</form>
</body>
<script type="text/javascript">
    $(function () {
        var tableconfig = {
            method: 'get',
            toolbar: '#toolbar',
            cache: false,
            height: 650,
            striped: true,
            pagination: false,
            sidePagination: 'client',
            search: true,
            showColumns: false,
            showRefresh: false,
            showExport: false,
            clickToSelect: true,
            singleSelect : false,
            columns:
                [
                    {
                        checkbox: true
                    },
                    {field: "code", title: "科室代码", align: "center", valign: "middle"},
                    {field: "name", title: "科室名称", align: "center", valign: "middle"},
                    {field: "id", title: "操作", align: "center", valign: "middle",
                        formatter: function (value, row, index) {
                            var buttonarray = new Array();
                            buttonarray[0] = '<button type="button" class="RoleOfedit btn btn-primary  btn-sm" style="margin-right:15px;">绑定评价科室调查问卷</button>';
                            return buttonarray.join('');
                        },
                        events:{
                            'click .RoleOfedit': function (e, value, row, index) {
                                $("#deptid").val(row.code);
                                $("form[name=form1]").submit()
                            }
                        }}
                ],
            url: getRootPath_web() + '/dept/selectAllDept'
        }

        $('#reportTable').bootstrapTable(tableconfig);
        $('#modalTable').on('shown.bs.modal', function () {
            // 执行一些动作...
            $('#referdeptable').bootstrapTable('resetView');
        })

        $("#btn_sure").on('click',function () {
            var deptrows =  $("#reportTable").bootstrapTable('getSelections')
            var referdeptrows =  $("#referdeptable").bootstrapTable('getSelections')
            var deptid = '';
            var referdeptid = '';
            $(referdeptrows).each(function () {
                referdeptid = this.code;
            })
            $(deptrows).each(function () {
                deptid += this.code;
                deptid += ',';
            })
            $.post(getRootPath_web()+'/testPaper/copyEvalDeptPaper',{
                deptid:deptid,
                referdeptid:referdeptid
            },function (data) {
                if(data){
                    $('#modalTable').modal('hide')
                    bootbox.alert("复制成功");
                }else{
                    $('#modalTable').modal('hide')
                    bootbox.alert("复制失败");

                }
            },'json')
        })
    });

</script>
</html>